import * as THREE from "three";
// 引入动画库
import gsap from "gsap";

export default class FlyLine {
    constructor() {
        let linePoints = [
            new THREE.Vector3(1, 2, 1),
            new THREE.Vector3(4, 3, 1),
            new THREE.Vector3(6, 3, 1),
            new THREE.Vector3(12, 1, 1),
        ];

        // 创建曲线
        this.lineCurve = new THREE.CatmullRomCurve3(linePoints);
        // 根据曲线生成管道几何体
        this.geometry = new THREE.TubeGeometry(this.lineCurve, 100, 0.5, 2, false);
        // 设置管道材质
        // 配置纹理
        const textureLoader = new THREE.TextureLoader();
        this.texture = textureLoader.load("./textures/z_11.png");
        this.texture.repeat.set(1,2);
        this.texture.wrapS = THREE.RepeatWrapping;
        this.texture.wrapT = THREE.MirroredRepeatWrapping;
        this.material = new THREE.MeshBasicMaterial({
            // color:"#aaaeff"
            map:this.texture,
            transparent : true
        });

        // 创建物体
        this.mesh = new THREE.Mesh(this.geometry,this.material);

        gsap.to(this.texture.offset,{
            x:-1,
            duration:1,
            repeat:-1,
            ease:"none"
        })
    }
    remove() {
        this.mesh.remove();
        this.mesh.removeFromParent();
        this.mesh.geometry.dispose();
        this.mesh.material.dispose();
    }
}